package com.api.util;

import com.alibaba.fastjson.JSON;
import com.api.pojo.User;
import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @packageName: com.api.util
 * @name: SessionUtil
 * @description:
 * @author: 董定卓
 * @dateTime: 2019/6/20 15:34
 */
public class UserUtil {

    public static User getUserDetail() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String token = request.getParameter("token");
        if (token == null || StringUtils.isEmpty(token)) {
            return null;
        }
        String userStr = RedisUtil.getString(token);
        if (userStr == null || StringUtils.isEmpty(userStr)) {
            return null;
        }
        return JSON.parseObject(userStr, User.class);
    }

}
